//
//  LSZLearningVC.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/14.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZLearningVC.h"

@interface LSZLearningVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic,strong) UICollectionView * collectionView;
@property(nonatomic,strong) NSArray *  arrayName;
@end

@implementation LSZLearningVC
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden=NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"扶贫办公";
    self.arrayName = @[@"任务通知",@"扶贫政策",@"帮扶日志",@"项目管理",@"通讯录",@"基础数据",@"贫困户查询",@"神农事"];
    //导航颜色和背景
    UINavigationBar * bar = self.navigationController.navigationBar;
    bar.barTintColor = themeColor;
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:22]}];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumInteritemSpacing = 0.5;
    flowLayout.minimumLineSpacing = 0.5;
    flowLayout.sectionInset = UIEdgeInsetsMake(0.5,0,0.5, 0);//分别为上、左、下、右
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, ScreenWidth, ScreenHeight-NAVIGATION_BAR_HEIGHT) collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = RGBColor(236, 236, 236);
    //添加以下代码关闭估算行高
    [self.view addSubview:self.collectionView];
    [self.collectionView registerClass:[LSZPublicityFigureCollectionViewCell class] forCellWithReuseIdentifier:@"LSZPublicityFigureCollectionViewCell"];
    [self.collectionView registerClass:[LSZPartyCollectionViewCell class] forCellWithReuseIdentifier:@"LSZPartyCollectionViewCell"];
}
#pragma mark <UICollectionViewDataSource>
#pragma mark - 设置有几个区
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
#pragma mark - 设置每个区有几个
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    // 定义的轮播器视图
    return 1+self.arrayName.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        LSZPublicityFigureCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZPublicityFigureCollectionViewCell" forIndexPath:indexPath];
        cell.imageViewBack.image = [UIImage imageNamed:@"学习banner"];
        return cell;
    }else{
        LSZPartyCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZPartyCollectionViewCell" forIndexPath:indexPath];
        cell.labelTitle.text = self.arrayName[indexPath.row-1];
        cell.imageViewIcon.image = [UIImage imageNamed:self.arrayName[indexPath.row-1]];
        return cell;
    }
}
#pragma mark - 点击进入详情页
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        
    }else if (indexPath.row == 1){
        LSZNoticeParentViewController * vc = [[LSZNoticeParentViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
//        LSZStudyPlanViewController * vc = [[LSZStudyPlanViewController alloc]init];
//        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 2){
        LSZLiteratureViewController * VC = [[LSZLiteratureViewController alloc]init];
        UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
        backItem.title=@"扶贫政策";
        self.navigationItem.backBarButtonItem = backItem;
        VC.comeStyle = @"1";
        [self.navigationController pushViewController:VC animated:YES];
    }else if(indexPath.row == 3){
        
        if ([[_MyCenter myJobId] isEqualToString:@""]) {
            [LSZRequestData initWithPersonalCenter:^(BOOL isOK, NSString * string, NSDictionary * dic) {
                if (isOK == YES) {
                    if ([dic[@"jobId"] isEqualToString:@"6"]) {
                        LSZAssistLogViewController * vc = [[LSZAssistLogViewController alloc]init];
                        [self.navigationController pushViewController:vc animated:YES];                    }else{
                            [self promptInformation:@"您没有权限查看!"];
                        }
                }else{
                    [self promptInformation:string];
                }
            }];
        }else{
            if ([[_MyCenter myJobId] isEqualToString:@"6"]) {
                LSZAssistLogViewController * vc = [[LSZAssistLogViewController alloc]init];
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                [self promptInformation:@"您没有权限查看!"];
            }
        }
//        LSZVideoClassViewController * vc = [[LSZVideoClassViewController alloc]init];
//        UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
//        backItem.title=@"视频专题";
//        self.navigationItem.backBarButtonItem = backItem;
//        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 4){
        LSZIndustrialClassificationVC * vc = [[LSZIndustrialClassificationVC alloc]init];
        UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
        backItem.title=@"项目管理";
        self.navigationItem.backBarButtonItem = backItem;
        [self.navigationController pushViewController:vc animated:YES];
//        LSZTheWalkmanViewController * vc = [[LSZTheWalkmanViewController alloc]init];
//        UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
//        backItem.title=@"随身听";
//        self.navigationItem.backBarButtonItem = backItem;
//        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 5){//通讯录
        LSZAddressBookVC * vc = [[LSZAddressBookVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 6){
        LSZBasicDataViewController * vc = [[LSZBasicDataViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 7){//贫困户查询
        LSZPoorHouseholdEnquiriesVC * vc = [[LSZPoorHouseholdEnquiriesVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else{
        LSZNetworkLoadViewController * vc = [[LSZNetworkLoadViewController alloc]init];
        vc.url = @"http://211.142.203.238:1880/client/ssoAuth.action?username=13511111111&password=96E79218965EB72C92A549DD5A330112";
        vc.titleStr = @"神农事";
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark - cell大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    if (indexPath.row == 0) {
        return CGSizeMake(ScreenWidth, 200);
    }else{
        CGFloat width = (ScreenWidth -2) / 4;
        return CGSizeMake(width, width);
    }
}
#pragma mark - 提示信息
-(void)promptInformation:(NSString *)string
{
    AlertKuangView * alert = [AlertKuangView new];
    [alert moveJingGaoKuang:string :self.view];
}
@end
